package com.feifan.common.utils.baiduai;


import com.feifan.common.config.BaiDuFace;

import java.util.HashMap;

/**
 * 人脸操作工具类
 * @author: Alex
 * @create: 2020-09-19 17:24
 **/
public class FaceUtils {

    /**
     * 人脸注册
     * @param image 人脸图片
     * @param userId 用户id
     * @param userName 用户姓名
     * @return
     */
    public static String addUser(String image, String groupId, String userId, String userName) {
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("user_info", userName);
        options.put("quality_control", BaiDuFace.getQualityControl());
        options.put("liveness_control", BaiDuFace.getLivenessControl());
        options.put("action_type", "REPLACE");

        String imageType = "BASE64";

        // 人脸注册
        return BaiDuAiResult.errorMessage(FaceClientUtil.getClient().addUser(image, imageType, groupId, userId, options).toString());
    }

    /**
     * 查询人脸
     * @param image 人脸图片
     * @param userId 用户id
     * @param group 用户组
     * @return
     */
    public static String search(String image, String userId, String group) {
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("max_face_num", "1");
        options.put("match_threshold", BaiDuFace.getMatchThreshold());
        options.put("quality_control", BaiDuFace.getQualityControl());
        options.put("liveness_control", BaiDuFace.getLivenessControl());
        options.put("user_id", userId);
        options.put("max_user_num", "1");

        String imageType = "BASE64";

        // 人脸搜索
        return BaiDuAiResult.errorMessage(FaceClientUtil.getClient().search(image, imageType, group, options).toString());
    }

}
